package com.wangwei.basic;

import edu.princeton.cs.algs4.StdOut;

/**
 *
 */
public class FixedCapacityStackOfStrings {

    private String[] a;
    private int N;

    public FixedCapacityStackOfStrings(int cap){
        a = new String[cap];
    }

    public boolean isEmpty(){
        return N == 0 ;
    }

    public int size(){
        return N;
    }

    public void push(String item){
        a[N++]= item;
    }

    public String pop(){
        return a[--N];
    }

    public static void test(String exp) {
        String[] arr = exp.split(" ");
        FixedCapacityStackOfStrings s;
        s =new FixedCapacityStackOfStrings(100);
//        while(!StdIn.isEmpty()){
        for(String item :arr){
//            String item = StdIn.readString();
            if(!item.equals("-"))
                s.push(item);
            else if(!s.isEmpty()) StdOut.println(s.pop() +"");
        }
        StdOut.println("("+ s.size() + " left on stack)");
    }

    public static void main(String[] args) {
        String exp="to be or not to - be - - that - - - is";
        test(exp);
    }
}
